package welsir.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import welsir.entity.dos.Article;
import welsir.entity.dos.ArticleClass;
import welsir.entity.vo.ResultMessage;
import welsir.mapper.ArticleClassMapper;
import welsir.mapper.ArticleMapper;
import welsir.util.ResultUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Genius
 * @date 2023/03/08 00:41
 * web端文章分类接口
 **/
@RestController
@RequestMapping("/webArticleClass")
@Api(value = "web端文章分类Controller")
public class WebArticleClassController {
    @Resource
    private ArticleMapper articleMapper;

    @Resource
    private ArticleClassMapper articleClassMapper;

    /**
     * 根据分类id获取分类名称
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id获取分类名称")
    @GetMapping("/getArticleClassNum/{id}")
    public ResultMessage<Integer> getArticleClassNum(
            @PathVariable("id") Integer id
    ){
        QueryWrapper<Article> wrapper= new QueryWrapper<Article>();
        wrapper.eq("sort_class", id);
        return ResultUtil.data(articleMapper.selectCount(wrapper));
    }

    /**
     * 获取全部分类列表
     * @return
     */
    @ApiOperation(value = "获取全部分类列表")
    @GetMapping("/getArticleClassList")
    public ResultMessage<List<ArticleClass>> getArticleClassList(
    ){
        return ResultUtil.data(articleClassMapper.selectList(null));
    }
}
